package com.baidu.recognition.controller;

import com.baidu.recognition.config.baidu.real.websocket.CustomWebSocketListener;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author liuzhiqiang
 */
@RestController
@Slf4j
@CrossOrigin
@Api(tags = {"实时语音识别--webSocket"})
@RequestMapping("real")
public class RealTimeVoiceController {
    @Autowired
    private CustomWebSocketListener customWebSocketListener;

    @ApiOperation(value = "socket测试准版语音识别")
    @PostMapping("webSocket")
    public String webSocket(MultipartFile file) {
        customWebSocketListener.connect();
        customWebSocketListener.setInputStream(file);
        while (customWebSocketListener.getWebSocket() == null) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        customWebSocketListener.sendFrame();
        return "已发送";
    }
}
